{ "cells": [ { "cell_type": "markdown", "id": "762816f4-26b8-48de-81a0-e4da844b40f9", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "# Peak Picking" ] }, { "cell_type": "raw", "id": "798e0492-4fc9-42b9-9a71-8d25db10813f", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ ".. currentmodule:: massdash" ] }, { "cell_type": "markdown", "id": "7083fef7-4e52-48d7-9f5f-f2950eb2848e", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "One of the powerful tools of *MassDash* is the ability to perform peak picking on the chromatograms. " ] }, { "cell_type": "raw", "id": "8ea1a1a6-e2d6-4f1c-82d0-890ba5cf883d", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "All supported peak pickers are located in the :py:mod:`peakPicking` module" ] }, { "cell_type": "markdown", "id": "6af37340-a7c6-4c17-b35e-53f09e35168a", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Currently supported peak pickers are:" ] }, { "cell_type": "raw", "id": "8fff8f03-92c2-4eb5-8865-0cbefdbbd94e", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "\n", "1. :py:class:`~peakPickers.MRMTransitionGroupPicker`\n", "2. :py:class:`~peakPickers.pyMRMTransitionGroupPicker`\n", "3. :py:class:`~peakPickers.ConformerPeakPicker`" ] }, { "cell_type": "raw", "id": "335fc53c-889f-4a75-9465-652d537220dc", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "The general outline for any MassDash peak picker is to:\n", "\n", "1. Initiate the peak picking object\n", "2. Set the parameters (specific to each peak picker)\n", "3. use the :py:func:`~peakPicking.GenericPeakPicker.pick` function to perform peak picking\n", "4. Visualize results" ] }, { "cell_type": "code", "execution_count": 1, "id": "86969d27-c510-4edc-81ce-15b46f137ad5", "metadata": { "editable": true, "nbsphinx": "hidden", "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "id": "a6c65b1c-9ef5-4e9a-bb34-60d7782495e4", "metadata": { "editable": true, "nbsphinx": "hidden", "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "# Please run this before executing any cell\n", "import os\n", "os.chdir(\"../../test/test_data/\") #### Insert path to data, this is the path to the tutorial data. " ] }, { "cell_type": "code", "execution_count": 3, "id": "44224d51-a667-431f-9e62-9e964fa5f8f2", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "from massdash.loaders import SqMassLoader\n", "import os\n", "pep = \"NKESPT(UniMod:21)KAIVR(UniMod:267)\"\n", "charge = 3\n", "loader = SqMassLoader(dataFiles=[\"xics/test_chrom_1.sqMass\"], rsltsFile=\"osw/test_data.osw\")\n", "transitionGroup = list(loader.loadTransitionGroups(pep, charge).values())[0]\n", "transitionGroupFeatures = loader.loadTransitionGroupFeaturesDf(pep, charge)" ] }, { "cell_type": "markdown", "id": "f6834e5b-7ca5-42d7-b9e7-9d9a41c8ddda", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "If the above code does not look familliar, please look at previous notebooks." ] }, { "cell_type": "markdown", "id": "e15b83f1-3c70-4483-a71d-5707d8d76a5e", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "## MRMTransitionGroupPicker" ] }, { "cell_type": "raw", "id": "4a88c62c-4dc9-4eae-96fe-7ea742164710", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "The :py:class:`~peakPickers.MRMTransitionGroupPicker` picker class is a wrapper around the ``pyopenms MRMTransitionGroupPicker`` object. This is the same peak picker that is used in ``OpenSwath``. " ] }, { "cell_type": "markdown", "id": "3f4ed176-0e32-4964-947e-cd5aa31a395e", "metadata": { "editable": true, "raw_mimetype": "", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### 1. Initiate MRMTransitionGroupPicker Object" ] }, { "attachments": {}, "cell_type": "raw", "id": "e37e6a62-0961-4a09-b6c4-649853f4a705", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Different peak pickers are initiated differently. \n", "The :py:class:`~peakPickers.MRMTransitionGroupPicker` requires one argument 'smoother' which is the smoothing that should be applied to the transition group before picking. This can be one of `sgolay`, `gauss` or `original` (no smoothing) and arguments for the smoother. Additional arguments specifying the smoothing can be supplied following. Below are some examples on initiating an :py:class:`~peakPickers.MRMTransitionGroupPicker` object" ] }, { "cell_type": "code", "execution_count": 4, "id": "b631fd51-1179-42a6-ad0e-a52b8736b088", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "from massdash.peakPickers import MRMTransitionGroupPicker\n", "\n", "noSmoothing = MRMTransitionGroupPicker(\"original\") # No smoothing\n", "guassSmoothing = MRMTransitionGroupPicker(\"gauss\", gauss_width=50.0) # Gaussian smoothing\n", "sgolaySmoothing = MRMTransitionGroupPicker(\"sgolay\", sgolay_frame_length = 11, sgolay_polynomial_order=3) #Sgolay smoothing " ] }, { "cell_type": "markdown", "id": "77cd71f8-1d03-46d2-8946-b0620e396fcb", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "For the following example we will use the sgolay smoother as this is the default for OpenSwath." ] }, { "cell_type": "raw", "id": "f7261649-4370-4ae2-90f7-fff2d48ad519", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Additional parameters can be set using the :py:func:`~peakPickers.MRMTransitionGroupPicker.setGeneralParameters` method." ] }, { "cell_type": "raw", "id": "9323fdaa-d006-40ad-a3f3-9c7c6dc9db72", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ ".. automethod:: massdash.peakPickers.MRMTransitionGroupPicker.setGeneralParameters\n", " :noindex:\n" ] }, { "cell_type": "markdown", "id": "87263415-dbde-43e7-99e6-30d6b730bc5c", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### 2. Customize Parameters" ] }, { "cell_type": "markdown", "id": "e7e84ef8-94ef-4b8a-a3c6-356a0efbab20", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "Here to cap ourselves at a reasonable number of features we will change `stop_after_feature` to 5. Also since we know that for this example the precursor signal is reasonable we will try turn on the `use_precursor` parameter. Since this precursor is quite high in intensity we can change the `signal_to_noise` cutoff to be more stringent. " ] }, { "cell_type": "code", "execution_count": 5, "id": "864e37a2-d359-439b-97be-c1bd45ef6429", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "sgolaySmoothing.setGeneralParameters(stop_after_feature=5, signal_to_noise=0.001, use_precursors='true')" ] }, { "cell_type": "markdown", "id": "b393cbde-95db-49b1-8cc3-19a631b8b581", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "### 3. Pick Precursor" ] }, { "cell_type": "raw", "id": "41a837b2-e164-4ebc-afcf-d7b5d89aa9fb", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "After we have set the parameters we can use the :py:func:`~PeakPickers.MRMTransitionGroupPicker.pick` function to pick the precursor" ] }, { "cell_type": "raw", "id": "372a1fd7-d5ba-450d-992c-a14826f85c82", "metadata": { "editable": true, "raw_mimetype": "text/restructuredtext", "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "All peak pickers implement the :py:func:`~PeakPickers.MRMTransitionGroupPicker.pick` function which requires a :py:class:`~structs.TransitionGroup` object and outputs a list of :py:class:`~structs.TransitionGroupFeature` objects." ] }, { "cell_type": "code", "execution_count": 6, "id": "e8c37da1-71c5-41e7-b857-6e760ad5d07d", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [], "source": [ "features = sgolaySmoothing.pick(transitionGroup)" ] }, { "cell_type": "markdown", "id": "63da344d-7c16-4775-a3b4-3336c8161cf6", "metadata": { "editable": true, "slideshow": { "slide_type": "" }, "tags": [] }, "source": [ "For easier inspection of the features, we can convert them to a pandas dataframe" ] }, { "cell_type": "code", "execution_count": 7, "id": "1c5d3c19-1aca-4357-bd7b-1fd73e38f7a8", "metadata": { "editable": true, "scrolled": true, "slideshow": { "slide_type": "" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "
| \n", " | leftBoundary | \n", "rightBoundary | \n", "areaIntensity | \n", "qvalue | \n", "consensusApex | \n", "consensusApexIntensity | \n", "
|---|---|---|---|---|---|---|
| 0 | \n", "843.5 | \n", "901.700012 | \n", "223735.421875 | \n", "None | \n", "865.628726 | \n", "None | \n", "
| 1 | \n", "818.099976 | \n", "843.900024 | \n", "65524.886719 | \n", "None | \n", "839.389013 | \n", "None | \n", "
| 2 | \n", "1177.900024 | \n", "1207.0 | \n", "32929.136719 | \n", "None | \n", "1196.055723 | \n", "None | \n", "
| 3 | \n", "1051.099976 | \n", "1087.5 | \n", "48799.734375 | \n", "None | \n", "1069.299988 | \n", "None | \n", "
| 4 | \n", "978.400024 | \n", "1011.099976 | \n", "19260.796875 | \n", "None | \n", "995.780439 | \n", "None | \n", "
| 5 | \n", "1112.5 | \n", "1152.5 | \n", "36867.34375 | \n", "None | \n", "1133.06705 | \n", "None | \n", "
\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"| \n", " | leftBoundary | \n", "rightBoundary | \n", "areaIntensity | \n", "qvalue | \n", "consensusApex | \n", "consensusApexIntensity | \n", "
|---|---|---|---|---|---|---|
| 0 | \n", "843.5 | \n", "901.700012 | \n", "1537205.913208 | \n", "None | \n", "None | \n", "235346.499471 | \n", "
| 1 | \n", "818.099976 | \n", "843.5 | \n", "425795.080078 | \n", "None | \n", "None | \n", "78247.752761 | \n", "
| 2 | \n", "1189.199951 | \n", "1203.800049 | \n", "2428.022644 | \n", "None | \n", "None | \n", "64678.458586 | \n", "
| 3 | \n", "1167.400024 | \n", "1189.199951 | \n", "226734.0625 | \n", "None | \n", "None | \n", "28407.271623 | \n", "
| 4 | \n", "1131.099976 | \n", "1156.5 | \n", "2091.005585 | \n", "None | \n", "None | \n", "10654.984463 | \n", "
\\n\"+\n", " \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n", " \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n", " \"
\\n\"+\n", " \"\\n\"+\n",
" \"from bokeh.resources import INLINE\\n\"+\n",
" \"output_notebook(resources=INLINE)\\n\"+\n",
" \"\\n\"+\n",
" \"\\n\"+\n \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n \"
\\n\"+\n \"\\n\"+\n \"from bokeh.resources import INLINE\\n\"+\n \"output_notebook(resources=INLINE)\\n\"+\n \"\\n\"+\n \"